#ifndef ___SOCKET__ADDR__20140427___
#define ___SOCKET__ADDR__20140427___

#include <string>
#include "OSType.h"

#ifdef OS_WINDOWS
#include <ws2def.h>
#else
#include <netinet/in.h>
#endif

enum EAddressFamily
{
    AF_Unix = 1,        // Local to host (pipes and file-domain)
    AF_IPv4 = 2,        // IP protocol family
    AF_IPv6 = 10,       // IP version 6
    AF_Unknown
};

class CSocketAddr
{
public:
	CSocketAddr();
	CSocketAddr(LPCSTR lpszIP, UInt16 wPort);
	CSocketAddr(LPCSTR lpszAddress);
	CSocketAddr(const struct sockaddr_in &address);
    CSocketAddr(const struct sockaddr_in6 &address6);
	
public:
	void SetAddress(const char *lpszIP, UInt16 wPort);
	void SetAddress(const char *lpszAddress);
	void SetAddress(const struct sockaddr_in &address);
    void SetAddress(const struct sockaddr_in6 &address6);
	
	struct sockaddr_in  GetSocketAddr() const;
    struct sockaddr_in6 GetSocketAddr6() const;
	std::string         GetIPString() const;
	UInt16              GetPort() const;
	std::string         GetAddrString() const;
    EAddressFamily      GetAddressFamily() const;
	
protected:
    union
    {
        struct sockaddr_in      m_sockAddr;
        struct sockaddr_in6     m_sockAddr6;
    };

    EAddressFamily              m_addressFamily;        // AF_IPv4/AF_IPv6
};

#endif
